package com.bill.common.user.action;

import org.springframework.beans.factory.annotation.Autowired;

import com.bill.common.user.dto.UserDTO;
import com.bill.common.user.service.IUserService;
import com.opensymphony.xwork2.ActionSupport;
import com.sinba.common.dto.PageDTO;

@SuppressWarnings("serial")
public class UserAction extends ActionSupport {
	@Autowired
	private IUserService userService;
	private PageDTO pageDTO;
	private UserDTO userDTO = new UserDTO();
	private Long[] ids;
    private String sord;
    private String sidx;
    private int page = 1;
    private int rows = 10;
    private boolean result;
	public boolean isResult() {
		return result;
	}
	public void setResult(boolean result) {
		this.result = result;
	}
	public PageDTO getPageDTO() {
		return pageDTO;
	}
	public void setPageDTO(PageDTO pageDTO) {
		this.pageDTO = pageDTO;
	}
	public UserDTO getUserDTO() {
		return userDTO;
	}
	public void setUserDTO(UserDTO userDTO) {
		this.userDTO = userDTO;
	}
	public Long[] getIds() {
		return ids;
	}
	public void setIds(Long[] ids) {
		this.ids = ids;
	}
	public String getSord() {
		return sord;
	}
	public void setSord(String sord) {
		this.sord = sord;
	}
	public String getSidx() {
		return sidx;
	}
	public void setSidx(String sidx) {
		this.sidx = sidx;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
    
	public String findPager(){
		int start = ( page - 1 ) * rows;
		userDTO.setStart( start );
		userDTO.setLimit( rows );
        pageDTO = userService.findPager(userDTO, sord, sidx);
        if(pageDTO!=null){
        	pageDTO.setPage( page );
        	pageDTO.setRows( rows );
        }
		return SUCCESS;
	}
	
	
	public String userLogin(){
		result=userService.userLogin(userDTO);
		return "result";
	}
	
	
	public String saveUser(){
		userService.saveUser(userDTO);
		return SUCCESS;
	}
	
	public String deleteUser(){
		userService.deleteUser(ids);
		return SUCCESS;
	}
	
	public String updatePassword(){
		userService.updatePassword(userDTO);
		return SUCCESS;
	}
	
	public String findUserInfo(){
		userDTO = userService.findUserInfo(userDTO.getUserId());
		
		return "userDTO";
	}
	
	public String loginNameExist(){
		result = userService.loginNameExist(userDTO.getLoginName());
		return "result";
	}
}
